package com.ebs.md.fxmonitor.marketmonitor.esper;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/esper/PassiveHitsNMLBasicFactStatement.java $
 *  $Revision: #2 $  $Change: 115956 $  $DateTime: 2012/10/18 15:01:23 $  $Author: Arik.Sher $
 */

import java.sql.Timestamp;
import java.util.List;

import org.apache.log4j.Logger;

import com.ebs.md.container.esper.AbsStatement;
import com.ebs.md.fxmonitor.marketmonitor.config.IOutOfRegionQuotingConfig;


public class OutOfRegionQuotingBasicFactStatement
extends AbsStatement<IOutOfRegionQuotingConfig>
{
	static final protected Logger s_logger = Logger.getLogger(OutOfRegionQuotingSingleFactStatement.class);

	protected Timestamp currTimeStamp;
		
	
	@Override
	protected String createEplExpression() 
	{
		String pairsClauseImplicit = buildEplClauseImplicitForMonitoredPairs();

		String regionName = getRegion();
		
		String str =
		String.format(eplExpressionText
				, config.getName()   	             //1. configuration name.
				, config.getBlackoutFrom(regionName) //2. start time.	
				, config.getBlackoutTo  (regionName) //3. end time.
				, regionName                         //4. blackout (this) region configuration
				, regionName                         //5. blackout (this) region configuration
				, config.getIsMonitored(regionName)  //6. isMonitoredFlag
				, pairsClauseImplicit
				);
		return str;
	}
	
	private String buildEplClauseImplicitForMonitoredPairs() {
		StringBuffer sb = new StringBuffer();
		
		List<String> pairs = config.getMonitoredPairsList();
		
		for ( String currPairName : pairs ) {
			sb.append(String.format(", '%s'", currPairName));
		}
		
		return sb.toString();
	}
	
}
